<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// 
//  search_model.php
//  www.6block.com
//  
//  Created by WillLee on 2011-06-20.
//  Copyright 2011 lishuzu. All rights reserved.
// 


class Search_model extends CI_model{
	function __construct(){
		parent::__construct();
		$this->load->model('Activity_model');
		$this->load->model('Goods_model');
		$this->load->model('Collection_model');
		$this->load->library('datacache');
		$this->userinfo = $this->session->userdata('userinfo');
	}
	
	function get_data_by_catid($catid){
		//page
		$_SGLOBAL = $this->config->item('SGLOBAL');
		$_SGLOBAL['multipage_config']['base_url'] = base_url().'/index/index/';
		//查询条件
		$this->db->where('endtime >=', now());
		$this->db->where('catid =', $catid);
		$this->db->where('status >=', 0);
		
		$total_rows = $this->db->count_all_results('activity');
		$_SGLOBAL['multipage_config']['total_rows'] = $total_rows;
		$_SGLOBAL['multipage_config']['uri_segment'] = '4';
		$_SGLOBAL['multipage_config']['per_page'] = '50';
		$offset = $this->uri->segment($_SGLOBAL['multipage_config']['uri_segment']);

		$this->pagination->initialize($_SGLOBAL['multipage_config']);
		$data = array();
		
		$activitys = $this->Activity_model->get_activitys_by_catid($catid, $_SGLOBAL['multipage_config']['per_page'], $offset);
		foreach ($activitys as $key => $activity) {
			if (!$activity['goods']) {
				$activity['goods'] = $this->Goods_model->get_goods($activity['aid'], 5);
			}
			//是否已经收藏
			$activity['iscollected'] = in_array($activity['aid'], $myaids) ? 1 : 0;
			//加密
			$activity['key'] = md5($activity['aid'].'lishuzu7qiaor!@#');
			$activity['discount'] = explode('.', $activity['discount']);
			$activity['offset']['int'] = $activity['discount'][0];
			$activity['offset']['decimal'] = isset($activity['discount'][1]) ? $activity['discount'][1] : 0;
			$activity['starttime'] = date('Y-m-d H:i:s', $activity['starttime']);
			$activity['endtime'] = date('Y-m-d H:i:s', $activity['endtime']);
			$activity['dateline'] = date('Y-m-d H:i:s', $activity['dateline']);
			$data['activitys'][] = $activity;
		}
		$multi = $this->pagination->create_links();
		$data['multi'] = $multi;
		return $data;
	}
}
/* End of file search.php */
/* Location: ./application/controllers/search.php */

?>